package com.bjwl.wybx.controller.safty;

import com.bjwl.wybx.entity.Notice;
import com.bjwl.wybx.service.NoticeService;
import com.bjwl.wybx.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
<<<<<<< HEAD
import org.springframework.web.bind.annotation.GetMapping;
=======
>>>>>>> 70f7e19d6da4b30f0412d394b1171a015e63af36
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/safty/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;
    //添加公告
    @RequestMapping("/add")
    public Result add(Notice notice){
        try {
            //调用service层的添加公告的方法
            int num=noticeService.add(notice);
            if(num>0){
                return Result.success("发布公告成功");
            }
            return Result.fail("发布失败");

        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统升级中，发布失败");
        }
<<<<<<< HEAD
    }
//    获取所有公告
    @GetMapping("getNoticeDataList")
    public Result getNoticeDataList(){
        try {
            List<Notice> list = noticeService.getNoticeDataList();
            if(list!=null){
                return Result.success("查询成功！",list);
            }
            return Result.fail("查询为空");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统升级中，查询失败");
        }
=======

>>>>>>> 70f7e19d6da4b30f0412d394b1171a015e63af36
    }
    //查询某个角色的公告
    @RequestMapping("/queryByRoId")
    public Result queryByRoId(Integer ro_id){
        try {
            List<Notice> list=noticeService.queryByRoId(ro_id);
            if(list!=null){
                return Result.success("查询成功！",list);
            }
            return Result.fail("查询为空");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统升级中，查询失败");
        }
    }
    //查询某一条公告
    @RequestMapping
    public Result queryOne(Integer notice_id){
        try {
            //调用service层方法查询
            Notice notice=noticeService.queryOne(notice_id);
            if(notice!=null){
                return Result.success("查询成功！",notice);
            }
            return Result.fail("查询失败！");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统升级中！");
        }
    }
    //修改公告
    @RequestMapping("/update")
    public Result update(@RequestBody Notice notice){
        try {
            //调用service层方法进行修改
            int i=noticeService.update(notice);
            if(i>0){
                return Result.success("修改公告成功");
            }
            return Result.success("修改公告失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.success("系统正在升级，请稍后");
        }
    }
}
